import java.util.Scanner;

public class GuessNumber
{

    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);

        String sure = "";

        do
        {
            System.out.println("欢迎来到Java猜数字游戏, 请输入一个1-100之间的整数(你有7次猜测机会): ");

            int answer = (int) (Math.random()*100) + 1;
            // System.out.println("答案是(测试):" + answer);

            boolean flag = false;
            int chance = 7;

            while (chance > 0 && !flag)
            {
                int guess = sc.nextInt();

                System.out.println("你猜测的数字是: " + guess);

                if (guess > answer)
                {
                    System.out.println("你猜大了, 请重猜");
                    chance--;
                    System.out.println("你还有: " + chance + "次机会");
                }
                else if (guess == answer)
                {
                    System.out.println("恭喜, 你猜对了");
                    flag = true;

                    System.out.println("是否要重玩? (输入y重玩, 输入其它字符则退出游戏)");
                    sure = sc.next();
                    System.out.println(sure);
                }
                else
                {
                    System.out.println("你猜小了, 请重猜");
                    chance--;
                    System.out.println("你还有: " + chance + "次机会");
                }

            }

            if (chance == 0)
            {
                System.out.println("是否要重玩? (输入y重玩, 输入其它字符则退出游戏)");
                sure = sc.next();
                System.out.println(sure);
            }

        }
        while (sure.equalsIgnoreCase("y"));

        sc.close();

    }
}

